package com.jintoufs.web.action.common;

import com.jintoufs.service.sys.DictionaryService;
import com.jintoufs.service.sys.impl.DictionaryServiceImpl;
import org.springframework.stereotype.Repository;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.LinkedHashMap;
import java.util.Map;

@Repository
public class ApplicationStartListener implements ServletContextListener {
    private DictionaryService dictionaryService;

    public DictionaryService getDictionaryService() {
        return dictionaryService;
    }

    public void setDictionaryService(DictionaryService dictionaryService) {
        this.dictionaryService = dictionaryService;
    }

    public void contextInitialized(ServletContextEvent event) {
        ServletContext arg0=event.getServletContext();
        dictionaryService=(DictionaryServiceImpl) WebApplicationContextUtils.getWebApplicationContext(arg0).getBean("dictionaryService");
        Map<String , LinkedHashMap<String, String>> dic=dictionaryService.getdicMap();
        arg0.setAttribute("dic", dic);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }

}